home *** CD-ROM | disk | FTP | other *** search
/ Commodore Free 12 / Commodore_Free_Issue_12_2007_Commodore_Computer_Club.d64 / t.hex files 7 < prev    next >
File List  |  2023-02-26  |  8KB  |  249 lines

  1. u
  2. Hexfiles Part 7
  3. http://www.oldschool-gaming.com/
  4. By Jason Kelk
  5.  
  6. Okay, so what happened last time?
  7.  
  8. Ah, yes I remember, I was going to
  9. explain $D018 does, wasn't I?
  10.  
  11. Okay, well while I'm here I might as
  12. well explain some of the rest of the
  13. videochip at the same time. First off,
  14. there are some conventions that we'll
  15. use use here, the bits of a byte are 
  16. referred to as 0 for the lowest bit
  17. through to for the highest.
  18.  
  19. Okay, so as promised lets start with
  20. $D018, which is a pointer to where
  21. the screen and character set are
  22. stored. And before I go on, a little
  23. lesson in architecture is needed. The
  24. C64 has, as we know, 64K of memory but
  25. the VIC-II chip isn't able to use it
  26. all at once, instead it uses 1 of 4
  27. "banks" of 16K, bank 0 is the lowest,
  28. from the start of memory to $3FFF (and
  29. the default, so for now we will keep
  30. working in it) whilst bank 3 is the
  31. last, at $C000 to $FFFF.
  32.  
  33. A C64 character set contains 256
  34. characters, so with eight bytes per
  35. character thats a total of 2K needed
  36. and it's possible to point at any 2K
  37. block in the present bank. Bits 1, 2
  38. and 3 of $D018 control this, allowing
  39. the VIC II to see any one of the eight
  40. possible starting points for the
  41. character data and setting the bits to
  42. $0 will put the character set at $0000
  43. using $2 will mean the font
  44. is at $0800 all the way up (in steps
  45. of two) until we get to $E, which
  46. means $3800 has the font data.
  47.  
  48. Similarly, the C64 needs 1K for a
  49. screen and bits 4 to 7 of $D018 are
  50. used to represent where the screen is
  51. living. Since there are 16 possible
  52. screens in each bankading from, $0 will
  53. put it down at $0000 and $F locates it
  54. at $3C00. The actual default for $D018
  55. is $14, the upper 4 bits are set to $1
  56. so the screen is at $0400 & the lower 4
  57. are $4 so the fifth character set in is
  58. used, at $1000. The reason the C64
  59. defaults like this is because a
  60. "shadow" copy of the ROM character set
  61. is stored at $1000 with the lower case
  62. version at $1800.
  63.  
  64. A quick definition of shadowing is in
  65. order, I think. The C64 only has 64K
  66. of RAM but the ROM takes another 32K.
  67. Because the 6510 can't access more
  68. than 64K at any one time (it can only
  69. look at $0000 to $FFFF) the ROM has to
  70. exist within that space. But that would
  71. take up valuable memory from programs.
  72.  
  73. So the ROMs are all shadowed over
  74. other memory, the BASIC ROM is at
  75. $A000 to $C000 and if you try reading
  76. through that memory with the PEEK
  77. command you'll be able to see it. But
  78. it's *also* possible to store data
  79. under that memory, for example
  80. graphics, and not have the ROM
  81. overwrite it and if we point the
  82. VIC-II chip at it we don't see the
  83. ROM data, just our graphics.
  84.  
  85. This means that we get all the ROMs
  86. we need and *still* have the space
  87. they occupy in the RAM, they're there
  88. but in an insubstantial way, hence the
  89. name ROM shadow. The character set at
  90. $1000 works the other way around,if we
  91. point the VIC-II at it we only see the
  92. ROM font, no matter what data we put
  93. there. But we can happily put data into
  94. that RAM, read it out or run program
  95. code from there without that font
  96. affecting what we're doing (in fact,
  97. $1000 is a very commonly used area of
  98. memory for music routines for this
  99. reason, a convenient 4K block for two
  100. fonts that can't be used for graphics)
  101.  
  102. Another useful location is $D011 and
  103. it has a number of uses, bits 0,
  104. 1 and  are used to set the vertical
  105. smooth  scrolling and bit 3 controls
  106. the scroll masks, when this bit isn't
  107. set, the border extends into the
  108. screen area slightly and masks hides
  109. the edges of the screen so that the
  110. new data coming on can't be seen until
  111. it's ready. Bit  controls the screen,
  112. if it's set the screen is on,otherwise
  113. the border covers it. Turning the
  114. screen off may seem a little pointless
  115. but there are purposes, for example
  116. hiding the screen until the graphics
  117. have been set up.
  118.  
  119.  
  120. Bit 5 of $D011 will activate bitmap
  121. screen mode if set, instead of the
  122. normal 256 character set the VIC chip
  123. takes a block of 8,000 bytes, 8 for
  124. each character square of the screen,so
  125. really it's just like having a *very*
  126. large character set. Bitmap mode has a
  127. few disadvantages over normal screen
  128. modes, it's memory consuming (a
  129. bitmapped picture such as a loading
  130. screen needs 10,000 bytes of memory
  131. all told when the colour is added) and
  132. it's difficult to scroll.
  133. Not impossible, just difficult. The
  134. *advantage* of bitmaps are that they
  135. have more colours available to them.
  136. I will be covering the basics of bit-
  137. maps in more detail a little further on
  138.  
  139. $D016 has been covered before, we
  140. used it in the Ferris demo to scroll
  141. the message across the screen & smooth
  142. scrolling is the job of bits 0 to 2,
  143. along with bit 3 which controls the
  144. masks at the sides of the screen in the
  145. same way as $D011. Bit 4 is used to set
  146. multicolour mode, one of those little
  147. quirks of the C64's video system.
  148.  
  149. When multicolour mode is on the pixels
  150. don't just appear as they are stored,
  151. instead the bits are grouped together
  152. in twos horizontally & the 2 bit number
  153. they produce represents 1 of 4 colours.
  154. This reduces the horizontal resolution
  155. of the screen by half because each
  156. character is now only four pixels wide
  157. (physically they don't change size, but
  158. the pixels are now twice as wide) but
  159. we do have more colour control.
  160.  
  161. The character colour, in locations
  162. $D800 onwards, is used to control
  163. multicolour mode and, as we have done
  164. before, when we set it normally we have
  165. sixteen colours, values $00 to $0F. But
  166. multicolour mode allows us to mix
  167. standard characters and multicolour
  168. ones because the first eight colours
  169. (black, white, red, cyan, purple,
  170. green, dark blue and yellow, values $00
  171. to $07) will produce their normal eight
  172. pixel wide characters but using colours
  173. $08 to $0F produces those eight colours
  174. again but in multicolour mode. So where
  175. does the colour information for our two
  176. new colours come from? $D022 and $D023
  177. are the multicolour registers. They
  178. function just like $D021 (the back-
  179. ground colour) but only affect multi-
  180. color areas on characters using colors
  181. $08 to $0F.
  182. Our four possible colours therefore
  183. come from the character colour, $D021
  184. for the background colour and the two
  185. multicolours, giving four in total.
  186.  
  187. Bitmaps (and I said I'd get back to
  188. them, didn't I?) work a little
  189. differently. When we use bitmap mode,
  190. the screen becomes the colour info for
  191. the bitmap. So, if we set $D011 to $3B
  192. to switch bitmap mode on and $D018 to
  193. $18, we now have 1,000 "characters" on
  194. the screen, each with it's own 
  195. individual colours.  The lower 4 bits
  196. of the screen (in this example at
  197. $0400) represent one of the colours &
  198. the upper four a second, $00 will set
  199. both to black and $FF will make them
  200. light grey for example. But the most
  201. interesting use for bitmaps is with
  202. multicolour on, so we set $D016 to $18
  203. and now we have lots of colours.
  204.  
  205. Why? Well, at $0400 to $07E7 we have
  206. 1,000 bytes of colour information, 2
  207. colours per character. But in multi-
  208. colour bitmap mode we *also* have the
  209. $D800 colour map, as used by the screen
  210. normally to give us a third colour and
  211. the background for our forth. And the
  212. $D800 colours are not limited to the
  213. first seven as with multicolour
  214. characters, they can be any colour from
  215. $00 to $0F.
  216.  
  217. The only drawback to having this much
  218. colour (three colours per character
  219. square) is that there are some 10,000
  220. bytes of data required, 8,000 for the
  221. bitmap itself and 2,000 over two
  222. areas for the colour data, so moving
  223. it around is a no-no without some
  224. trickery which we will have to leave
  225. for a while yet.
  226.  
  227. Right, well thats the theory over with
  228. & indeed the article, but next time
  229. I'll be performing a more practical
  230. demonstration of how bitmaps work with
  231. some example code and a picture to play
  232. with.
  233.  
  234. In the meantime, a small challenge
  235. regarding $D018, can you work out what
  236. the values would be to put the screen
  237. at $3400 & the character data at $2800?
  238. Work it out on paper & check yourself
  239. against the start of the next part and
  240. if you have any questions, suggestions
  241. or whatever about this or C64 code in
  242. general, contact me.
  243.  
  244. Commodore Free
  245. would like to thank Jason for
  246. allowing the reprinting of the
  247. HEXFILES the article was taken from
  248. http://www.oldschool-gaming.com/
  249.